# -*- coding: utf-8 -*-
# (save as TCPServer_Bonus.py):
'''
python的win2扩展。
(save as 'Bonus_Excel_Win32com.py')
'''
# http://sourceforge.net/projects/pywin32/
# -*- coding: utf-8 -*-

import socketserver
import Bonus_Excel_Win32com

class MyTCPHandler(socketserver.BaseRequestHandler):
    """
    The RequestHandler class for our server.

    It is instantiated once per connection to the server, and must
    override the handle() method to implement communication to the
    client.
    """

    def handle(self):
        # self.request is the TCP socket connected to the client
        self.data = self.request.recv(1024).strip()
        print("{} wrote:".format(self.client_address[0]))
        name_file = self.data.decode('utf-8')
        print(name_file)
        b = Bonus_Excel_Win32com.bonus()
        b.bonus_101217(name_file)
        # just send back the same data, but upper-cased
        self.request.sendall(self.data.upper())

if __name__ == "__main__":
    HOST, PORT = "localhost", 10086

    # Create the server, binding to localhost on port 10086
    server = socketserver.TCPServer((HOST, PORT), MyTCPHandler)

    # Activate the server; this will keep running until you
    # interrupt the program with Ctrl-C
    server.serve_forever()
